package org.cpar.compiler.nodes;

import java.util.List;

import org.antlr.runtime.Token;
import org.antlr.runtime.tree.Tree;
import org.cpar.compiler.CPARNode;
import org.cpar.compiler.ICodeWriter;

public class MonitorBlock extends CPARNode {

	private MonitorBlock(MonitorBlock b) {
		super(b);
	}

	public MonitorBlock(Token nextToken) {
		super(nextToken);
	}

	@Override
	public void accept(ICodeWriter writer) {
		writer.visit(this);
	}

	@Override
	public Tree dupNode() {
		return new MonitorBlock(this);
	}

	public CPARNode getName() {
		return ((CPARNode) getChild(0));
	}

	@SuppressWarnings("unchecked")
	public List<CPARNode> getVarDeclarations() {
		return (List<CPARNode>) ((CPARNode) getChild(1)).getChildren();
	}

	@SuppressWarnings("unchecked")
	public List<AnsiFunction> getFunctions() {
		return ((List<AnsiFunction>) ((CPARNode) getChild(2)).getChildren());
	}

	public CPARNode getInitializeStatement() {
		CPARNode initilizeNode = (CPARNode) getChild(3);
		if (initilizeNode.getChildCount() > 0)
			return (CPARNode) initilizeNode.getChild(0);
		return null;
	}
}
